package com.chenjt.springai.six_functionCalling.controller;



import com.chenjt.springai.six_functionCalling.repository.ChatHistoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2025/5/29 16:01
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class CustomerServiceController {


    private final ChatClient serviceChatClient;

    private final ChatHistoryRepository chatHistoryRepository;

    @RequestMapping(value="/service",produces = "text/html;charset=utf-8")
    public Flux<String> service(String prompt,String chatId){

        // 1.保存会话id
        chatHistoryRepository.save("service",chatId);
        // 2.请求模型
        return serviceChatClient.prompt()
                .user(prompt)
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, chatId))
                .stream() // 流式调用
                .content();

    }


}
